const path = require('path')
const express = require('express')
const { createProxyMiddleware } = require('http-proxy-middleware')
const {rewriteList,serverProxy} = require('../config/webpack.server')
const app = express()
const port = process.env.port || 9091

app.use(express.static('./build'))
rewriteList.forEach(it=>{
  app.use(`/${it.path}`,(req, res)=>{
    res.sendFile(path.join(__dirname, `../build/${it.to}/index.html`));
  })
})
serverProxy.forEach(it=>{
  app.use(it.api,createProxyMiddleware({
    target:it.target,
    changeOrigin: true,
    secure:false,
    pathRewrite:it.pathRewrite
  }))
})

app.listen(port,()=>{
  console.log('Server started at http://localhost:' + port);
})